/**
 * JAVACC DEMO 1.0
 */
package com.sale.plugins;

import com.apache.api.vo.ParamsVo;
import com.apache.cache.util.Validator;
import com.apache.database.constant.SpringContextLoader;
import com.apache.database.db.IDao;
import com.apache.database.model.MethodParam;
import com.apache.ius.plugin.CustomMethodPlugin;
import org.apache.log4j.Logger;

import java.util.Map;

/**
 * 发售交易-行情统计分析插件
 *
 * @author Administrator 创建时间：2017-1-5
 */
public class SaleQuotationUpdatePluginImpl implements CustomMethodPlugin {

    private Logger log = Logger.getLogger(getClass());

    private IDao iusPubDao;

    public Object afterInvoke(Map<String, Object> param) {
        String proNo = String.valueOf(param.get("trsOrder.proNo"));
        if (Validator.isNull(proNo)) {
            String modelType = String.valueOf(param.get("modelTypes"));
            String str[] = modelType.split(",");
            for (int i = 0; i < str.length; i++) {
                String fixpre = str[i].substring(2);
                proNo = String.valueOf(param.get(fixpre + ".proNo"));
                break;
            }
        }
        exeQutotaion(proNo);
        return null;
    }

    public Object beforeInvoke(Map<String, Object> param) {
        String proNo = String.valueOf(param.get("trsOrder.proNo"));
        if (Validator.isNull(proNo)) {
            String modelType = String.valueOf(param.get("modelTypes"));
            String str[] = modelType.split(",");
            for (int i = 0; i < str.length; i++) {
                String fixpre = str[i].substring(2);
                proNo = String.valueOf(param.get(fixpre + ".proNo"));
                break;
            }
        }
        exeQutotaion(proNo);
        return null;
    }

    /**
     * TODO 简单描述该方法的实现功能（可选）.
     *
     * @see com.apache.api.manager.PluginConnector#execute(com.apache.api.vo.ParamsVo)
     */
    public Object execute(ParamsVo param) throws Exception {

        return null;
    }

    /**
     * 规则校验入口（专门给系统公式规则提供的）
     *
     * @param paramsVo
     */
    public void run(ParamsVo paramsVo) {
        beforeInvoke(paramsVo.getParams());
    }

    public void setIusPubDao(IDao iusPubDao) {
        this.iusPubDao = iusPubDao;
    }

    private boolean exeQutotaion(String proNo) {
        if (Validator.isNull(proNo)) {
            return false;
        }
        MethodParam params = new MethodParam("ByQuotationUpdate", "", "","com.apache.ius.sql.DymicMapper");
        params.setParams("proNo", proNo);
        if (Validator.isEmpty(iusPubDao)) {
            iusPubDao = (IDao) SpringContextLoader.getBean("iusPubDao");
        }
        iusPubDao.select(params);
        log.info(proNo + "-行情刷新完成");
        return true;
    }

    public Object doInvoke(Map<String, Object> param) {
        return null;
    }

}
